package com.have.blog.admin.controller;

import com.have.blog.admin.annotation.operationLogger.OperationLogger;
import com.have.blog.admin.domain.dto.FeedbackDto;
import com.have.blog.admin.service.FeedbackService;
import com.have.blog.base.exception.ThrowableUtils;
import com.have.blog.base.validator.group.GetList;
import com.have.blog.base.validator.group.Update;
import com.have.blog.base.wrapper.CommonPage;
import com.have.blog.base.wrapper.Wrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Api(value = "用户反馈相关接口", tags = {"用户反馈相关接口"})
@RequestMapping("/feedback")
@Slf4j
public class AdminFeedbackController {

    @Autowired
    FeedbackService feedbackService;

    @ApiOperation(value = "获取反馈列表", notes = "获取反馈列表", response = String.class)
    @PostMapping("/getList")
    public Wrapper<CommonPage<FeedbackDto>> getList(@Validated({GetList.class}) @RequestBody FeedbackDto feedbackDto, BindingResult result) {

        // 参数校验
        ThrowableUtils.checkParamArgument(result);
        log.info("获取反馈列表: {}", feedbackDto);
        return feedbackService.getPageList(feedbackDto);
    }

    @OperationLogger(value = "编辑反馈")
    @ApiOperation(value = "编辑反馈", notes = "编辑反馈", response = String.class)
    @PostMapping("/edit")
    public Wrapper edit(@Validated({Update.class}) @RequestBody FeedbackDto feedbackDto, BindingResult result) {

        // 参数校验
        ThrowableUtils.checkParamArgument(result);
        log.info("编辑反馈: {}", feedbackDto);
        return feedbackService.editFeedback(feedbackDto);
    }

    @OperationLogger(value = "批量删除反馈")
    @ApiOperation(value = "批量删除反馈", notes = "批量删除反馈", response = String.class)
    @PostMapping("/deleteBatch")
    public Wrapper delete(@RequestBody List<Integer> uids, BindingResult result) {

        // 参数校验
        log.info("批量删除反馈: {}", uids);
        return feedbackService.deleteBatchFeedback(uids);
    }
}
